//
//  TabBarViewController.m
//  SmartCup
//
//  Created by Kendama on 2017/5/16.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "TabBarViewController.h"
#import "RadiateViewController.h"
#import "SportViewController.h"
#import "SleepViewController.h"
#import "SettingViewController.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTabBarItem];

}


- (void)setTabBarItem
{
    
    RadiateViewController *radiateVC = [[RadiateViewController alloc] init];
    radiateVC.tabBarItem.title = MyNSLocalizedString(@"辐射");
    radiateVC.navigationItem.title = MyNSLocalizedString(@"辐射");
    
    SportViewController *sportVC = [[SportViewController alloc] init];
    sportVC.tabBarItem.title = MyNSLocalizedString(@"运动");
    sportVC.navigationItem.title = MyNSLocalizedString(@"运动");
    
    SleepViewController *sleepVC = [[SleepViewController alloc] init];
    sleepVC.tabBarItem.title = MyNSLocalizedString(@"睡眠");
    sleepVC.navigationItem.title = MyNSLocalizedString(@"睡眠");
    
    SettingViewController *settingVC = [[SettingViewController alloc] init];
    settingVC.tabBarItem.title = MyNSLocalizedString(@"设置");
    settingVC.navigationItem.title = MyNSLocalizedString(@"设置");
    
    self.viewControllers = @[[self giveMeVC:radiateVC andImgName:@"tab_icon_radiate" andSelectedImgName:@"tab_icon_radiate_pre"],
                             [self giveMeVC:sportVC andImgName:@"tab_icon_exercise" andSelectedImgName:@"tab_icon_exercise_pre"],
                             [self giveMeVC:sleepVC andImgName:@"tab_icon_sleep" andSelectedImgName:@"tab_icon_sleep_pre"],
                             [self giveMeVC:settingVC andImgName:@"tab_icon_set" andSelectedImgName:@"tab_icon_set_pre"]
                            ];

    
}

- (UIViewController *)giveMeVC:(UIViewController *)VC andImgName:(NSString *)imgName andSelectedImgName:(NSString *)selImgName
{
    //    nav.tabBarItem = [[UITabBarItem alloc] initWithTitle:VC.tabBarItem.title image:[self removeRendering:imgName] tag:0];
    VC.tabBarItem = [[UITabBarItem alloc] initWithTitle:VC.tabBarItem.title image:[self removeRendering:imgName] selectedImage:[self removeRendering:selImgName]];
    [VC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]}
                                  forState:UIControlStateNormal];
    [VC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:238/255.0 green:98/255.0 blue:100/255.0 alpha:1]} forState:UIControlStateHighlighted];
    //    [nav.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -12)];
    //    nav.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor yellowColor]};
    return VC;
}


/**
 *  快速创建Nav
 */
- (UINavigationController *)giveMeNavWithVC:(UIViewController *)VC andImgName:(NSString *)imgName andSelectedImgName:(NSString *)selImgName
{
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:VC];
//    nav.tabBarItem = [[UITabBarItem alloc] initWithTitle:VC.tabBarItem.title image:[self removeRendering:imgName] tag:0];
    nav.tabBarItem = [[UITabBarItem alloc] initWithTitle:VC.tabBarItem.title image:[self removeRendering:imgName] selectedImage:[self removeRendering:selImgName]];
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]}
                                  forState:UIControlStateNormal];
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:238/255.0 green:98/255.0 blue:100/255.0 alpha:1]} forState:UIControlStateHighlighted];
//    [nav.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -12)];
//    nav.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor yellowColor]};
    return nav;
}


/**
 *  返回取消渲染的image
 */
- (UIImage *)removeRendering:(NSString *)imageName
{
    UIImage * image = [UIImage imageNamed:imageName];
    return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}



@end
